/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShPropertyEmployeeDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShPropertyEmployeeService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShPropertyEmployee;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShPropertyEmployeeService 实现类
 * @author KongXiangyu
 * @since 2015-09-07
 */
@Service("shPropertyEmployeeService")
public class ShPropertyEmployeeServiceImpl extends BaseServiceImpl<ShPropertyEmployee, Long> implements ShPropertyEmployeeService {
	

    @Resource
    private ShPropertyEmployeeDao shPropertyEmployeeDao;

    public BaseDao<ShPropertyEmployee, Long> getDao() {
        return shPropertyEmployeeDao;
    }

	@Override
	public DataGrid dataGrid(ShPropertyEmployee employee,PageHelper page) {
		if(null == employee) employee = new ShPropertyEmployee();
		
		DataGrid grid = new DataGrid();
		
		if(!StringUtils.isBlank(page.getOrder())){
			employee.setOrderFieldType(page.getOrder());
		}
		if(!StringUtils.isBlank(page.getSort())){
			employee.setOrderField(page.getSort());
		}
	 // int startIndex = (page.getPage() - 1) * page.getRows();
	   //int endIndex = page.getPage() * page.getRows();
	   Integer count = shPropertyEmployeeDao.selectEntryListCount(employee);
	   grid.setTotal(count+ 0l);
		
	   if (grid.getTotal() > 0 && grid.getTotal() > page.getStartIndex()) {
		   	  employee.setStartIndex(page.getStartIndex());
		   	 employee.setEndIndex(page.getEndIndex());
	    	  List<ShPropertyEmployee> rows =  shPropertyEmployeeDao.selectEntryList(employee);
	    	  grid.setRows(rows);
	    }
	   
		return grid;
	}

}